/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.farmcode.base.web;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author oiprado
 */
public class Session {
  /**
     * Metodo ue devuelve un valor de la session
     * @param llave
     * @return
     */
    public<T> T getValue(String key) {
         HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
         return (T)httpServletRequest.getSession().getAttribute(key);
    }
    
    /**
     * remueve el atributo de la session
     * @param llave
     */
    public void remove(String key) {
         HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
         httpServletRequest.getSession().removeAttribute(key);
    }
    
    /**
     * 
     * Método que colcoca valores en la session
     * @param llave
     * @param valor
     */
    public void setValue(String key, Object value) {
         HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
         httpServletRequest.getSession().setAttribute(key, value);         
    }
}
